Repository navigation
aggregator: versioned item-history capture for forecasting (#3981 slice 1) - #5133
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a06bc4ac47
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| effort: effortOf(item.labels), | ||
| blockedBy: [...(item.blockedBy ?? [])].sort(), | ||
| }; | ||
| if (item.parentRef) captured.parentRef = item.parentRef; |
There was a problem hiding this comment.
Preserve issue-versus-PR identity in captured history
When the project pool contains both issues and PRs, capture discards ProjectPoolItem.contentKind, and weeklyCompletions subsequently counts every open-to-closed/merged transition. An issue closure plus its merged PR therefore produces two completed units, while even an unmerged PR closure counts as delivery. The forecasting design’s §1 defines the unit as a native child issue and explicitly excludes PRs. Preserve the content kind in stored items and filter the forecasting completion series accordingly; otherwise readers cannot reliably recover the intended unit from this history.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8ea49db: capture now stores kind from ProjectPoolItem.contentKind on every item (structural gate accepts "issue"/"pr", absent treated as issue for pre-kind lines), and weeklyTransitions skips PR items entirely — a merged or unmerged-closed PR is never a completed unit and an issue + its PR cannot double-count. New test: "PR transitions never count as completed units".
| const complete = cutoffs.filter((c) => c.coverage.complete && !c.coverage.unavailable); | ||
| const weeks: WeeklyTransitions[] = []; | ||
| for (let i = 1; i < complete.length; i++) { | ||
| const before = new Map(complete[i - 1]!.items.map((item) => [item.ref, item.state])); |
There was a problem hiding this comment.
Exclude intervals that cross missing weekly observations
When a complete W1 cutoff is followed by an unavailable W2 cutoff and a complete W3 cutoff, filtering first makes W1 and W3 adjacent. Every closure observed across those two weeks is then returned as W3’s single weekly completion bucket. The existing missing-source test explicitly exercises this case. This does not merely exclude a missing week: it attributes potentially missing-week completions to a supposedly complete week, corrupting the weekly throughput distribution required by design §1. Keep the gap as an unknown interval and resume weekly buckets only when both bounding observations cover an uninterrupted week.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8ea49db: weeklyTransitions now only forms a week from two consecutive stored cutoffs that are both complete. An incomplete cutoff breaks the chain; the next complete cutoff becomes a fresh baseline, so a closure spanning the gap is attributed to no week rather than to the next complete bucket. The missing-source test now asserts exactly this (gap closure uncounted; buckets resume at the first uninterrupted pair).
| for (const cutoff of ordered) { | ||
| const item = cutoff.items.find((i) => i.ref === ref); | ||
| if (item && item.blockedBy.includes(blockerRef)) { | ||
| const last = ordered[ordered.length - 1]!; | ||
| const ageMs = Date.parse(last.cutoffAt) - Date.parse(cutoff.cutoffAt); |
There was a problem hiding this comment.
Reset blocker age after an observed edge removal
If an edge exists at W1, is absent at a complete W2 cutoff, and is added again at W3, this scan returns W1 and a 14-day lower-bound age for the newly added edge. That is not a lower bound on the current blocking episode and can incorrectly satisfy the design’s seven-day unresolved-blocker stall signal. Determine the first observation of the current episode, resetting it when a complete cutoff establishes that the edge was absent, rather than using the earliest occurrence across all history.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8ea49db: blockerFirstObserved now ages the current episode — a complete cutoff that observes the item without the edge resets the episode start, so a re-added edge is first-observed at its re-observation, and an edge absent at the last complete cutoff returns null. New tests cover the reset (W1 present → W2 absent → W3 re-added: age runs from W3) and the removed-edge null case.
Three Codex findings on PR #5133, all fixed: (1) capture ProjectPoolItem.contentKind as ItemHistoryItem.kind and count only issue items as completed units — a merged/closed PR no longer counts, and an issue plus its PR cannot double-count; (2) weeklyTransitions only forms a week from two consecutive complete cutoffs — an incomplete cutoff breaks the chain, so transitions spanning a missing week are attributed to no week instead of the next complete bucket; (3) blockerFirstObserved ages the current episode — a complete cutoff observing the item without the edge resets the episode, and an edge gone at the last complete cutoff returns null. Tests: missing-source expectation corrected, new PR-units test, new episode-reset tests; bun test test/item-history.test.ts 10 pass.
Summary
Slice 1 of #3981 (forecasting slice 1): the versioned item-history source the forecasting design (
doc/2026-11-01T21-07-00Z_design_pm-stack_forecasting.md§1/§3/§5) names as its prerequisite — one reusable history seam for #1281 flow analytics and forecasting, not a second collector/store.pm-stack/aggregator/src/item-history.ts:ItemHistoryCutoff(schema v1): at each weekly cutoff, the observed item scope — ref/repo/number, GitHub state, Project Status (kept distinct from GitHub state),effort/*, parent/epic membership, sorted blocker edges — plus a coverage block (source,fetchedAt,complete,unavailable).captureItemHistory(pool, coverage, cutoffAt): pure capture from the liveProjectPoolItemprojection the aggregator already fetches; the coverage weekly anchor is the natural clock for whoever wires the writer.ItemHistoryStore: append-only JSONL, one cutoff per line, deduped bycutoffAt, malformed lines skipped on read; file location viaITEM_HISTORY_FILEor the aggregator data dir. Ownership/retention documented in the module header (13-month raw retention per the snapshots.ts precedent).weeklyTransitions/weeklyCompletions(observed transitions between consecutive complete cutoffs only) andblockerFirstObserved(first-observed edge with a labelled lower-bound age — no fabricated exact event times).unavailable: true, complete: falseand is excluded from derivations — distinct from a complete zero-completion week, which is preserved as a real 0. A reopened item leaves the completed count until it closes again.test/item-history.test.ts, 7 tests, all passing locally withbun test): capture mapping incl. membership change, reopen cycle, zero-week preservation, missing-source exclusion, first-observed blocker lower bound, store round-trip/dedupe/bad-line resilience.Not in this slice
Evidence
bun test test/item-history.test.ts— 7 pass, 0 fail. Full typecheck runs in CI (a fresh worktree has nonode_modules, sobunx tsccannot resolve bun types locally).Refs #3981 (slice 1; the issue stays open for the writer wiring).
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.